﻿using L6_RegionNavigation.ViewLifetime.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Navigation.Regions;
using System.Collections.ObjectModel;

namespace L6_RegionNavigation.ViewLifetime.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private readonly IRegionManager regionManager;

        public ObservableCollection<Person> People { get; set; }

        public DelegateCommand<Person> ShowPerson { get; set; }

        public MainWindowViewModel(IRegionManager regionManager)
        {
            this.regionManager = regionManager;

            People = new ObservableCollection<Person>();
            for (int i = 0; i < 5; i++)
            {
                Person person = new Person();
                person.Id = i;
                person.Name = "姓名" + i.ToString();
                person.Age = 20 + i;

                People.Add(person);
            }

            ShowPerson = new DelegateCommand<Person>(p =>
            {
                NavigationParameters parameters = new NavigationParameters();
                parameters.Add("model", p);

                this.regionManager.RequestNavigate("ContentRegion", "PersonAttrributeView", parameters);
            });
        }
    }
}
